package org.xshop.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.xshop.model.TMemberFootmark;
import org.xshop.service.ITMemberFootmarkService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import top.ibase4j.core.base.AppBaseController;
import top.ibase4j.core.util.DataUtil;
import top.ibase4j.core.util.WebUtil;

/**
 * <p>
 * 我的足迹  前端控制器
 * </p>
 *
 * @author ShenHuaJie
 * @since 2018-05-21
 */
@Controller
@RequestMapping("/app/member")
@Api(tags = "MemberFootMark", value = "我的足迹接口", description = "我的足迹接口")
public class TMemberFootmarkController extends AppBaseController<TMemberFootmark, ITMemberFootmarkService> {
    @PostMapping(value = "/getFootmarkList.api")
    @ApiOperation(value = "查询我的足迹", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object query(HttpServletRequest request) {
        Map<String, Object> param = WebUtil.getParameter(request);
        Long id = getCurrUser(request);
        if (DataUtil.isNotEmpty(id)) {
            param.put("createBy", id);
        }
        Assert.notNull(param.get("createBy"), "用户ID不能为空");
        Object result = service.queryAll(param);
        return setSuccessModelMap(result);
    }


    @PostMapping(value = "delFootmark.api")
    @ApiOperation(value = "删除我的足迹", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object del(HttpServletRequest request) {
        TMemberFootmark param = WebUtil.getParameter(request, TMemberFootmark.class);
        Long id = getCurrUser(request);
        if (DataUtil.isNotEmpty(id)) {
            param.setCreateBy(id);
        }
        Assert.notNull(param.getCreateBy(), "用户ID不能为空");
        service.delAll(param);
        return setSuccessModelMap();
    }
}